{extend name="shop/new/Member/base" /}

{block name="main"}
<div class="v-main-right fl">
                    <div class="v-container" style="padding: 20px 14px 60px;">
                        <!--page-->
                        <div class="pic-box">
                            <ul class="clearfix j-body">

                            </ul>
                            <div class="page clearfix">
                                <div class="M-box3 m-style fr"></div>
                            </div>
                        </div>
                        <!--page-->
                    </div>
                </div>
<input type="hidden" id="page_index">
{/block}

{block name="javascript"}

<script>
    require(['common',"dialog"], function (common,dialog) {
        LoadingInfo(1);
        function LoadingInfo(page_index) {
            $("#page_index").val(page_index);
            $.ajax({
                    type: "post",
                    url:  __URL(SHOPMAIN + "/member/goodsCollectionList"),
                    data: {
                        "page_index": page_index
                    },
                    success: function (data) {
                        var html = '';
                        if (data["data"].length > 0) {
                            for (var i = 0; i < data["data"].length; i++) {
                                html+='<li>';
                                if(data["data"][i]['del_status']==1){
                                    html+='<a target="_blank" href="javascript:void(0);">';
                                }else{
                                    html+='<a target="_blank" href="' + __URL('SHOP_MAIN/goods/goodsInfo?goodsid=' + data["data"][i]['fav_id']) + '">';
                                }
                                if(data["data"][i]['goods_image']){
                                    html+='<img src="'+__IMG(data["data"][i]['goods_image'])+'" alt="">';
                                }else{
                                    html += '<img src="__TEMP__/shop/new/public/image/missing.png"  alt="">';
                                }
                                if(data["data"][i]['del_status']==1){
                                    html+='<p class="goodsTitle">'+data["data"][i]['goods_name']+'<span style="color: red">【该商品已下架】</span></p>';
                                }else{
                                    html+='<p class="goodsTitle">'+data["data"][i]['goods_name']+'</p>';
                                }
                                html+='</a>';
                                html+='<div class="pic-info clearfix">';
                                html+='<div class="price fl">￥&nbsp;<span>'+data["data"][i]['log_price']+'</span></div>';
                                html+='<div class="cancel fr"><a href="javascript:void(0);" class="cancelCollection" data-id="'+data["data"][i]['fav_id']+'" data-type="goods">取消收藏</a></div>';
                                html+='</div>';
                                html+='</li>';
                            }
                        }else{
                            $(".pic-box").css('display','none');
                            html1 = '';
                            html1 += '<div class="no-fav-result clearfix">';
                            html1 +='<div class="no-pic">';
                            html1 +='<img src="__TEMP__/shop/new/public/image/membercenter/Notcollect.png" alt="">';
                            html1 +='</div>';
                            html1 +='<div class="no-result-tips">';
                            html1 +='<p class="big-font">你还没收藏过商品哦</p>';
                            html1 +='<p><a target="_blank" href="{:__URL(\'SHOP_MAIN/index/index\')}" class="blue">去随便逛逛吧</a>，看看有没有喜欢的</p>';
                            html1 +='</div>';
                            html1 +='</div>';
                           $('.v-container').html(html1);
                        }
                        $(".j-body").html(html);
                        common.Pages('.M-box3', data['total_count'], data["page_count"], page_index, LoadingInfo);
                    }
                }
            )
            ;
        }
        $('.j-body').on('click','.cancelCollection',function(){
            var fav_id = $(this).data('id');
            var  fav_type = $(this).data('type');
            layer.confirm('你确定取消该商品的收藏？', {
                btn: ['确定', '取消']//按钮
            }, function (index) {
                layer.close(index);
                $.ajax({
                    url : __URL(SHOPMAIN + "/components/cancelCollGoodsOrShop"),
                    type : "post",
                    data : {
                        "fav_id" : fav_id,
                        "fav_type" : fav_type
                    },
                    success : function(data) {
                        if (data["code"] > 0) {
                            layer.msg('取消成功',{icon: 1, time: 2000}, LoadingInfo($('#page_index').val()));
                        }else{
                            layer.msg('取消失败');
                        }
                    }
                });
            });

        });

    });

</script>
{/block}
